using System;
using System.Windows.Forms;
using FridayShopping.DataModel;

namespace FridayShopping.UI
{
	/// <summary>
	/// Summary description for CategoriesForm.
	/// </summary>
	public class CategoriesForm : System.Windows.Forms.Form, IListViewForm
	{
		private System.Windows.Forms.MainMenu mainMenu1;

		private Categories categories;
		private System.Windows.Forms.ImageList imageList;
		private System.Windows.Forms.ToolBar toolBar;
		private System.Windows.Forms.ToolBarButton toolBar_delete;
		private System.Windows.Forms.ToolBarButton toolBar_new;
		private System.Windows.Forms.ToolBarButton toolBar_edit;
		private System.Windows.Forms.ListView categoriesList;
		private System.Windows.Forms.ColumnHeader columnHeader_name;
		private System.Windows.Forms.ColumnHeader columnHeader_key;
		private Microsoft.WindowsCE.Forms.InputPanel inputPanel1;

        private ListFormManager listFormManager;
	
		public CategoriesForm()
		{
			InitializeComponent();

			categories = Database.Instance.Categories;
			toolBar.ImageList = imageList;
			toolBar.Buttons[0].ImageIndex = 0;
			toolBar.Buttons[1].ImageIndex = 1;
			toolBar.Buttons[2].ImageIndex = 2;

            listFormManager = new ListFormManager(this, categoriesList, categories);

		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CategoriesForm));
			this.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.toolBar = new System.Windows.Forms.ToolBar();
			this.toolBar_new = new System.Windows.Forms.ToolBarButton();
			this.toolBar_delete = new System.Windows.Forms.ToolBarButton();
			this.toolBar_edit = new System.Windows.Forms.ToolBarButton();
			this.imageList = new System.Windows.Forms.ImageList();
			this.categoriesList = new System.Windows.Forms.ListView();
			this.columnHeader_key = new System.Windows.Forms.ColumnHeader();
			this.columnHeader_name = new System.Windows.Forms.ColumnHeader();
			this.inputPanel1 = new Microsoft.WindowsCE.Forms.InputPanel();
			// 
			// toolBar
			// 
			this.toolBar.Buttons.Add(this.toolBar_new);
			this.toolBar.Buttons.Add(this.toolBar_delete);
			this.toolBar.Buttons.Add(this.toolBar_edit);
			this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick);
			// 
			// toolBar_new
			// 
			this.toolBar_new.Enabled = ((bool)(resources.GetObject("toolBar_new.Enabled")));
			this.toolBar_new.ImageIndex = ((int)(resources.GetObject("toolBar_new.ImageIndex")));
			this.toolBar_new.Visible = ((bool)(resources.GetObject("toolBar_new.Visible")));
			// 
			// toolBar_delete
			// 
			this.toolBar_delete.Enabled = ((bool)(resources.GetObject("toolBar_delete.Enabled")));
			this.toolBar_delete.ImageIndex = ((int)(resources.GetObject("toolBar_delete.ImageIndex")));
			this.toolBar_delete.Visible = ((bool)(resources.GetObject("toolBar_delete.Visible")));
			// 
			// toolBar_edit
			// 
			this.toolBar_edit.Enabled = ((bool)(resources.GetObject("toolBar_edit.Enabled")));
			this.toolBar_edit.ImageIndex = ((int)(resources.GetObject("toolBar_edit.ImageIndex")));
			this.toolBar_edit.Visible = ((bool)(resources.GetObject("toolBar_edit.Visible")));
			// 
			// imageList
			// 
			this.imageList.Images.Add(((System.Drawing.Image)(resources.GetObject("resource"))));
			this.imageList.Images.Add(((System.Drawing.Image)(resources.GetObject("resource1"))));
			this.imageList.Images.Add(((System.Drawing.Image)(resources.GetObject("resource2"))));
			this.imageList.Images.Add(((System.Drawing.Image)(resources.GetObject("resource3"))));
			this.imageList.Images.Add(((System.Drawing.Image)(resources.GetObject("resource4"))));
			this.imageList.ImageSize = ((System.Drawing.Size)(resources.GetObject("imageList.ImageSize")));
			// 
			// categoriesList
			// 
			this.categoriesList.Columns.Add(this.columnHeader_key);
			this.categoriesList.Columns.Add(this.columnHeader_name);
			this.categoriesList.Enabled = ((bool)(resources.GetObject("categoriesList.Enabled")));
			this.categoriesList.FullRowSelect = true;
			this.categoriesList.Location = ((System.Drawing.Point)(resources.GetObject("categoriesList.Location")));
			this.categoriesList.Size = ((System.Drawing.Size)(resources.GetObject("categoriesList.Size")));
			this.categoriesList.Text = resources.GetString("categoriesList.Text");
			this.categoriesList.View = System.Windows.Forms.View.Details;
			this.categoriesList.Visible = ((bool)(resources.GetObject("categoriesList.Visible")));
			this.categoriesList.ItemActivate += new System.EventHandler(this.categoriesList_ItemActivate);
			this.categoriesList.SelectedIndexChanged += new System.EventHandler(this.categoriesList_SelectedIndexChanged);
			// 
			// columnHeader_key
			// 
			this.columnHeader_key.Text = resources.GetString("columnHeader_key.Text");
			this.columnHeader_key.TextAlign = ((System.Windows.Forms.HorizontalAlignment)(resources.GetObject("columnHeader_key.TextAlign")));
			this.columnHeader_key.Width = ((int)(resources.GetObject("columnHeader_key.Width")));
			// 
			// columnHeader_name
			// 
			this.columnHeader_name.Text = resources.GetString("columnHeader_name.Text");
			this.columnHeader_name.TextAlign = ((System.Windows.Forms.HorizontalAlignment)(resources.GetObject("columnHeader_name.TextAlign")));
			this.columnHeader_name.Width = ((int)(resources.GetObject("columnHeader_name.Width")));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			// 
			// CategoriesForm
			// 
			this.ClientSize = ((System.Drawing.Size)(resources.GetObject("$this.ClientSize")));
			this.Controls.Add(this.categoriesList);
			this.Controls.Add(this.toolBar);
			this.Enabled = ((bool)(resources.GetObject("$this.Enabled")));
			this.Font = ((System.Drawing.Font)(resources.GetObject("$this.Font")));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Location = ((System.Drawing.Point)(resources.GetObject("$this.Location")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Text = resources.GetString("$this.Text");
			this.Visible = ((bool)(resources.GetObject("$this.Visible")));
			this.Load += new System.EventHandler(this.CategoriesForm_Load);

		}
		#endregion

		#region IListViewForm implementation
		public ToolBarButton DeleteButton
		{
			get
			{
				return toolBar_delete;
			}
		}

		public ToolBarButton NewButton
		{
			get
			{
				return toolBar_new;
			}
		}

		public ToolBarButton EditButton
		{
			get
			{
				return toolBar_edit;
			}
		}

		public ToolBarButton UpButton
		{
			get
			{
				return null;
			}
		}

		public ToolBarButton DownButton
		{
			get
			{
				return null;
			}
		}

		public IItemPropertiesForm CreatePropertiesForm(ItemBase item)
		{
			return new CategoryPropertiesForm((Category)item);
		}

		#endregion

		#region Form Event Handlers
		private void CategoriesForm_Load(object sender, System.EventArgs e)
		{
			listFormManager.FillListView();

			listFormManager.EnableDisableItems();		
		}

		private void categoriesList_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			listFormManager.EnableDisableItems();
		}

		private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			listFormManager.ToolbarEventsHandler(e);
		}

		private void categoriesList_ItemActivate(object sender, System.EventArgs e)
		{
			listFormManager.HandleEditItemEvent();
		}
		#endregion

	}
}
